CleanTalk Anti-Spam "send_feedback" API method description
This method should only be used to send the result of manual moderation to the CleanTalk server. It doesn't check anything for spam. The method accepts feedback only for requests made no more than 7 or 45 days ago (if an Additional Package is activated).
Request
Data JSON Example
{
"method_name":"send_feedback",
"auth_key":"your_acccess_key",
"feedback":"4e8bc562bdaed613107d8b8695:0;4bd0105024bbaf60c57176b766e:1"
}
Data Processing
Necessary information about the data processing.
Parameter | Explanation |
---|---|
HTTP Method | POST |
Data format | JSON |
URL | https://moderate.cleantalk.org/api3.0/send_feedback |
Required Parameters
These parameters are required.
Parameter | Explanation |
---|---|
method_name | Must be "send_feedback". |
auth_key | Access key. To obtain a key please get an account here |
feedback | A string like: "<request_id1>:<0/1>;<request_id2>:<0/1>;<request_id3>:<0/1>;" , where <0/1> the moderator's decision to approve or disapprove the request with the request_id identifier (1 - NOT SPAM, 0 - SPAM). |
Response
Response example
The server's response is independent of the platform.
{
"recieved" : 1,
"comment" : "OK"
}
Response Explanation
Key | Explanation |
---|---|
recieved | "0" - if the request is rejected, "1" - if the request is accepted. |
comment | The response from the server, if everything is fine, then "OK". |
Code Examples
Using Wget
CLI example
wget -O- --post-data='{"method_name":"send_feedback", "auth_key":"your_acccess_key", "feedback":"4e8bc562bdaed613107d8b8695:0;4bd0105024bbaf60c57176b766e:1"}' https://moderate.cleantalk.org/api3.0/send_feedback
Using PHP
PHP backend
Download the CleanTalk library here. The library folder must be placed in the same path as the PHP file. Also, you can install the library via Composer.
<?php use Cleantalk\Cleantalk; use Cleantalk\CleantalkRequest; require_once (dirname(__FILE__) . '/lib/Cleantalk.php'); require_once (dirname(__FILE__) . '/lib/CleantalkRequest.php'); require_once (dirname(__FILE__) . '/lib/CleantalkResponse.php'); require_once (dirname(__FILE__) . '/lib/CleantalkHelper.php'); /** * Send feedback to the CleanTalk server. Returns int of successfully gained feedback on success, * false otherwise. * @param $feedback_list * @return false|int */ function cleantalk_send_feedback($feedback_list = array()) { if ( !is_array($feedback_list) ) { return false; } //reformat array to string $feedback_string = ''; foreach ($feedback_list as $key => $value) { $feedback_string .= sprintf("%s:%d;",$key, $value); } if ( empty($feedback_string) ) { return false; } // Set URL $config_url = 'http://moderate.cleantalk.org/api3.0/send_feedback'; // Set CleanTalk auth key $auth_key = 'your_key'; $ct_request = new CleantalkRequest(array( // General 'auth_key' => $auth_key, // Additional 'feedback' => $feedback_string, )); $ct = new Cleantalk(); $ct->server_url = $config_url; $response = $ct->sendFeedback($ct_request); // You can read server comment if you want with $response->comment return (bool)$response->received; } // Create a feedback list from collected request ids. Set 0 if visitor is spammer, 1 if not. $feedback_list = array( '28ahajhavvd2bdu8sajhadib2kajsbdu' => 0, 'u8sajhadib2kajsbdu28ahajhavvd2bd' => 1, 'sbdu28ahajhavvu8sajhadib2kajd2bd' => 1 ); // Send the list via function. This will "1" if success, "0" otherwise. var_dump(cleantalk_send_feedback($feedback_list));
Using Python
Python Backend
import hashlib
import ipaddress
import json
import os
from urllib.request import Request, urlopen
import requests
from datetime import datetime
"""
# It should be a key for DataBase API service to use spam_check method, look https://cleantalk.org/my/bill/api
# The best practice is to keep access key in the OS ENV, however you can specify this directly.
"""
CLEANTALK_AUTH_KEY = os.getenv('CLEANTALK_TEST_API_KEY')
def construct_feedback_request_string(_feedback_list):
feedback_data_string = ''
for feedback_record in _feedback_list:
if 'request_id' not in feedback_record \
or 'feedback' not in feedback_record \
or feedback_record['feedback'] not in ('0', '1', 0, 1):
continue
feedback_data_string += feedback_record['request_id'] + ':' + feedback_record['feedback'] + ';'
return feedback_data_string
def cleantalk_send_feedback(auth_key, feedback_data_string):
"""
Run send_feedback API method request via POST HTTP method.
:param string auth_key: your auth key
:param string feedback_data_string: String of feedback data
:return: dict of results or false on errors
"""
response_out = {
'status': '',
'error_msg': '',
'api_response': ''
}
if feedback_data_string == '':
response_out['status'] = 'error'
response_out['error_msg'] = 'No valid data found'
return response_out
url = 'https://moderate.cleantalk.org/api3.0/send_feedback'
headers = {'content-type': 'application/json;'}
values = {
"method_name": "send_feedback",
"auth_key": auth_key,
"feedback": feedback_data_string
}
try:
data = json.dumps(values, separators=(',', ':'))
request = Request(url, data.encode('utf-8'), headers)
response = urlopen(request, timeout=8)
response_bytes = response.read()
response_str = response_bytes.decode('utf-8')
response_parsed = json.loads(response_str)
response_out['status'] = 'success'
response_out['api_response'] = response_parsed
except BaseException as e:
response_out['status'] = 'error'
response_out['error_msg'] = 'Request error: ' + e.args[0]
return response_out
"""
# Example of multi records check via POST. Set a list of entities of ip/email and run the function.
"""
feedback_list = [
{
'request_id': 'a2385b43f342ee2cb81f7af67bec4315',
'feedback': '1'
},
{
'request_id': 'a2385b43f342ee2cb81f7af67bec4311',
'feedback': '0'
}
]
feedback_string = construct_feedback_request_string(feedback_list)
print(
cleantalk_send_feedback(
CLEANTALK_AUTH_KEY,
feedback_string
)
)
# will return object with results on success
# {
# 'status': 'success',
# 'error_msg': '',
# 'api_response': {
# 'comment': 'Ok.',
# 'received': 1
# }
# }
# will return object with results on errors
# {
# 'status': 'error',
# 'error_msg': 'Error message',
# 'api_response': ''
# }
Using NodeJS
NodeJS backend
const https = require('https');
const data = {
"method_name":"send_feedback",
"auth_key":"your_acccess_key",
"feedback":"4e8bc562bdaed613107d8b8695:0;4bd0105024bbaf60c57176b766e:1;"
};
sendFeedback(data).then((response) => {
// The attribute `response` will contain API result
console.log(response);
});
function sendFeedback(data) {
return new Promise((resolve, reject) => {
const options = {
method: 'POST'
};
const url = 'https://moderate.cleantalk.org/api3.0/send_feedback';
const request = https.request(url, options, result => onResponse(result, resolve, reject));
const onResponse = (result, resolve, reject) => {
const hasResponseFailed = result.status >= 400;
if (hasResponseFailed) {
reject(`Request to ${result.url} failed with HTTP ${result.status}`);
}
let responseData = '';
result.on('data', (chunk) => {
responseData += chunk;
});
result.on('end', () => {
resolve(responseData);
});
}
request.write(JSON.stringify(data));
request.end();
request.on('error', (err) => {
reject(`Encountered an error trying to make a request: ${err.message}`);
});
});
}
Using C#
The CleanTalk team would be grateful for your possible participation in the implementation of a detailed example for this language. If you would like to take part, please contact us via plugins@cleantalk.org
Backend (.NET)
- Download the package from GitHub: https://github.com/CleanTalk/csharp-antispam
- Add the relation link to the cleantalk.csharp package in your project.
- See existing test cases for example:
public const string AuthKey = "auth key";
[TestFixture]
public class SendFeedbackTests
{
private ICleantalk _cleantalk;
[Test]
public void SendFeedbackTest()
{
//send message1 to collect request_id
var req1 = new CleantalkRequest(AuthKey)
{
Message = "bla-bla-bla oh",
SenderInfo = new SenderInfo
{
Refferrer = "http://www.bbc.co.uk/sport",
UserAgent = "Opera/9.80 (Windows NT 6.1; WOW64) Presto/2.12.388 Version/12.12"
},
SenderIp = "91.207.4.192",
SenderEmail = "keanu8dh@gmail.com",
SenderNickname = "Mike",
//IsJsEnable = 1, redundant if use event_token
EventToken = "f32f32f32f32f32f32f32f32f32f32a2",
SubmitTime = 15
};
var res1 = _cleantalk.CheckMessage(req1);
Debug.WriteLine("req1=" + WebHelper.JsonSerialize(req1));
Debug.WriteLine("res1=" + WebHelper.JsonSerialize(res1));
//send message2 to collect request_id
var req2 = new CleantalkRequest(AuthKey)
{
Message = "This is great storm!!!",
SenderInfo = new SenderInfo
{
Refferrer = "http://www.bbc.co.uk/sport",
UserAgent = "Opera/9.80 (Windows NT 6.1; WOW64) Presto/2.12.388 Version/12.12"
},
SenderIp = "91.207.4.192",
SenderEmail = "keanu8dh@gmail.com",
SenderNickname = "Mike",
//IsJsEnable = 1, redundant if use event_token
EventToken = "f32f32f32f32f32f32f32f32f32f32a2",
SubmitTime = 15
};
var res2 = _cleantalk.CheckMessage(req2);
Debug.WriteLine("req2=" + WebHelper.JsonSerialize(req2));
Debug.WriteLine("res2=" + WebHelper.JsonSerialize(res2));
//send feedback
var feedbackReq = new CleantalkRequest(AuthKey)
{
Feedback = string.Format("{0}:1;{1}:0;", res1.Id, res2.Id)
};
var feedbackResp = _cleantalk.SendFeedback(feedbackReq);
Debug.WriteLine("feedbackReq=" + WebHelper.JsonSerialize(feedbackReq));
Debug.WriteLine("feedbackResp=" + WebHelper.JsonSerialize(feedbackResp));
Assert.IsNotNull(feedbackResp);
Assert.IsNotNullOrEmpty(feedbackResp.Comment);
Assert.IsTrue(feedbackResp.Received.GetValueOrDefault());
}
}
Using Golang
Golang backend
package main
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
)
var authKey string = "enter_your_key"
var configUrg string = "http://moderate.cleantalk.org/api3.0/send_feedback"
var agent string = "golang-api"
type feedbackInputData struct {
MethodName string `json:"method_name"`
AuthKey string `json:"auth_key"`
Feedback string `json:"feedback"`
}
type FeedbackResultData struct {
Recieved uint `json:"recieved"`
Comment string `json:"comment"`
}
func main() {
inputData := feedbackInputData{
MethodName: "send_feedback",
AuthKey: authKey,
Feedback: "your_request_id_1:1;your_request_id_2:1",
}
resultData, err := SendFeedback(inputData)
if err != nil {
fmt.Println(err.Error())
return
}
if resultData.Comment == "Ok." {
fmt.Println("Feedback received.")
return
}
fmt.Println("No feedback received.")
}
func SendFeedback(inputData feedbackInputData) (FeedbackResultData, error) {
inputDataBytes, err := json.Marshal(inputData)
var resultData FeedbackResultData
if err != nil {
return resultData, err
}
var body io.Reader = strings.NewReader(string(inputDataBytes))
req, err := http.NewRequest(http.MethodPost, configUrg, body)
if err != nil {
return resultData, err
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return resultData, err
}
defer resp.Body.Close()
answer, err := ioutil.ReadAll(resp.Body)
if err != nil {
return resultData, err
}
err = json.Unmarshal(answer, &resultData)
return resultData, nil
}
Related Links
Available features related to the method:
- CleanTalk GitHub account https://github.com/CleanTalk/php-antispam
It would also be interesting
- Anti-Spam API, Libraries, ClassesBuilt-in Libraries PHP Perl 5 Python 2/3 .NET 4.5 (C#) YII Framework YII 2 Framework Ruby ...
- CleanTalk Anti-Spam monitoring_services_get API MethodCleanTalk Anti-Spam "monitoring_services_get" API method description This method returns list of resources...
- CleanTalk Anti-Spam monitoring_services_add API MethodCleanTalk Anti-Spam "monitoring_services_add" API method description This method is used to add new URLs...